package id.co.rho.scoring.cid.server.command;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import id.co.rho.scoring.cid.client.command.CommandAction;
import id.co.rho.scoring.cid.client.command.CommandDispatcher;
import id.co.rho.scoring.cid.client.command.CommandResult;
import id.co.rho.scoring.cid.server.command.handler.CommandHandler;

public class CommandDispatcherImpl extends RemoteServiceServlet implements CommandDispatcher {

    public <T extends CommandResult> T execute(CommandAction<T> action) {
        CommandHandler<CommandAction, CommandResult> handler = CommandHandlerRepository.getHandler(action.getClass());
        CommandResult result = handler.execute(action);
        return (T) result;
    }

    @Override
    protected void doUnexpectedFailure(Throwable e) {
        e.printStackTrace();
    }

    @Override
    protected void checkPermutationStrongName() throws SecurityException {
        return;

    }
}
